define(['jquery', 'bootstrap'], function($, bootstrap){
    return {
        //初始化
        init: function(options){
            options.delete?this.delete(options.delete):'';
        },
        //监听删除事件
        delete: function(element){
            $(document).on("click", element, function(){
                return confirm($(this).text()+"？？？请再次确认！");
            });
        },
        //窗口提示
        modal: function(html){
            html = html || '请输入HTML代码';
            $('#modal').remove();
            $('body').append('<div class="modal fade" id="modal" data-bs-backdrop="static" data-bs-keyboard="false"><div class="modal-dialog modal-dialog-centered"><div class="modal-content text-center p-4 mb-0"><button type="button" class="btn-close position-absolute" data-bs-dismiss="modal" style="z-index:1;top:8px;right:8px;"></button><div>'+html+'</div></div></div></div>');
            new bootstrap.Modal($('#modal')).show();
        },
        //吐司提示
        toast: function(tips,timeout){
            tips = tips || 'ok';
            timeout = timeout || 3000;
            $('.toast-container').remove();
            $('body').append('<div class="toast-container position-fixed top-50 start-50 translate-middle"><div class="toast position-relative py-1" data-bs-delay="'+timeout+'"><p class="position-absolute" style="top:8px;right:8px;"><button class="btn-close"type="button" data-bs-dismiss="toast"></button></p><div class="toast-body text-center">'+tips+'</div></div></div>');
            new bootstrap.Toast($('.toast')).show();
        },
        //默认提示
        toastMini: function(tips){
            tips = tips || 'ok';
            $('.toast-container').remove();
            $('body').append('<div class="toast-container position-fixed top-50 start-50 translate-middle" style="width:200px"><div class="toast position-relative py-2 text-center border-0 bg-dark text-white" data-bs-delay="1000">'+tips+'</div></div>');
            new bootstrap.Toast($('.toast')).show();
        },
        //延迟跳转
        location: function(url){
            if(url){
                setTimeout(function(){
                    top.location.href = url;
                },1000);
            }
        },
        //json美化
        "jsonBeauty": function(selector) {
            selector = selector || this.defaults.selector;
            $(selector).each(function() {
                var jsonText = $(this).val();
                if(jsonText){
                    $(this).val(JSON.stringify(JSON.parse(jsonText), null, 4));
                }
            });
        }
    };
});